var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    start:0,
    message:'',
    remarkgoods:[],
    // orderList: [
    //   { "image": "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=596276033,515392538&fm=26&gp=0.jpg", "subTitle": "测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据ss", "orderColor": "22", "orderSize": "2222222222222222222222222222222222222222222222222223" }, 
    //   { "image": "https://ss1.bdstatic.com//it/u=596276033,515392538&fm=26&gp=0.jpg", "subTitle": "测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据ss", "orderColor": "22", "orderSize": "2222222222222222222222222222222222222222222222222223" }
    // ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id=options.id
    // let out=options.out
    // console.log(options)
    let goodslist;
    // let orderlist=wx.getStorageSync('orderlist')
    // let orderlistin=wx.getStorageSync('orderlistin')
    // console.log('orderlist:',orderlist)
    // console.log('orderlistin:',orderlistin)
    // if(out=='1'){
    //   console.log(1)
    //   goodslist=orderlist
    // }else{
    //   console.log(2)
    //   goodslist=orderlistin
    // }
    console.log('id:',id)
      util.request(api.MenuList).then(res => {
      console.log(res.data)
      if(res.errno==0){
        let datagoodsliat = res.data.datagoodsliat;
        console.log('res:',res)
        goodslist=datagoodsliat.map(item=>{
          console.log('item:',item)
          if(item.id==Number(id)){
            return item
          }
        });
        goodslist=goodslist.filter(item=>item)
        console.log('goodslist:',goodslist)
        this.setData({
          remarkgoods:goodslist[0]
         })
      }
      })


    
  //  let remarkgoods=goodslist[0];
  // console.log('remarkgoods:',remarkgoods)
   

   
    // 获取订单里面的
    // 外卖
    
    // 店内
    // util.request(api.OrderListIn).then(res => {
    
    // 展示评论
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  changeCheck(event) {
    this.setData({
      checked: event.detail,
    });
  },
  changeremark(e){
    // console.log(e);
    let contemt=e.detail
    this.setData({
      message:contemt
    })
  },
  publish(e){
    console.log('e',e.currentTarget.dataset.id)
    let id=e.currentTarget.dataset.id;
    let message=this.data.message;
    let start=this.data.start;
    // let content=changeremark()
    // let remarkgoods=this.remarkgoods;
    console.log(message)
    util.request(api.RemarkAdd,{
      openid:wx.getStorageSync('openid'),
      gid:id,
      content:message,
      start:start
    },"POST").then(res=>{
      if(res.errno==0){
        let remarklist=res.data.remarklist;
        wx.showModal({
          title: 'tip',
          content: '评论成功',
          success: function () {
            wx.navigateBack({
              delta: 1,
            })
          }
        })    
        console.log(remarklist)
      }
    })
  },
  setMessage(e){
    console.log('e:',e)
  },
  changeStar(e){
    let start=e.detail
    this.setData({
      start:start
    })
  }

})